<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
   xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
   xmlns:f="http://xmlns.jcp.org/jsf/core"
   xmlns:h="http://xmlns.jcp.org/jsf/html"
   xmlns:p="http://primefaces.org/ui"
   xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
   template="/WEB-INF/templates/business/supplier/template.xhtml">
   
   	<f:metadata>
	   	<f:viewParam name="tradeId" value="#{tradeController.id}"></f:viewParam>
	   	<f:viewParam name="bulletinId" value="#{bulletinHome3.id}"></f:viewParam>
	   	<f:event listener="#{tradeController.initConversation()}" type="preRenderView"></f:event>
   	</f:metadata>
   <ui:define name="supplier_head">
	   <style type="text/css">
			.label {
				width:120px;
				line-height:30px;	
				color: #333;
				text-align: right;
				padding-right:20px;
				text-align: right;
			}
			
			.value {
				font-style:normal;
				font-size: 16px;
				line-height:30px;
				color:#666666;				
				text-align:left;
				padding-left:20px;
			}
			h2{
   				text-align:center
   			}
   			.rowStyle{
	   			text-align: center;
	   			font-size:16px
   			}
   		</style>
   </ui:define>
   	<ui:define name="supplier_content">
   
		<h:form id="editForm">
			<p:panel id="panel" header="申请" style="margin-bottom:10px;">
			
		        <p:messages id="messages" closable="true">
		       		<p:autoUpdate />
		       	</p:messages>
		        
		       <ui:include src="/WEB-INF/templates/business/bulletinBasicInfo.xhtml" />
				
			</p:panel>
			
			<p:panel id="bulletinReqs" header="公告要求">
				<h:panelGrid columns="2" cellpadding="5"
					columnClasses="column1,column2">
					<p:outputLabel for="rootQualificationGroup" value="匹配规则" />
					<h:outputText id="rootQualificationGroup"
						style="font-size:16px;color:red"
						value="#{bulletinHome3.instance.qualificationGroup.relation.typeName}" />
				</h:panelGrid>
				<p:panel id="agentServiceReqs" header="服务事项要求"
					rendered="#{bulletinHome3.instance.qualificationGroup.getAgentServiceGroups().size() > 0}"
					style="margin-bottom:10px;">
					<p:repeat var="_serviceGroup"
						value="#{bulletinHome3.instance.qualificationGroup.getAgentServiceGroups()}"
						varStatus="_groupStatus">
						<p:panelGrid cellpadding="5"
							style=" margin-bottom: 10px;width:100%">
							<p:row style="width:100%">
								<p:column>
									<h2>服务事项要求组#{_groupStatus.index + 1}（#{_serviceGroup.relation.typeName}组）</h2>
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<p:panelGrid cellpadding="5" style="width:100%">
										<p:row styleClass="rowStyle">
											<p:column>
												服务事项名称
											</p:column>
											<p:column>
												对应资质大类
											</p:column>
										</p:row>

										<p:repeat var="_service"
											value="#{_serviceGroup.agentServices}">
											<p:row>
												<p:column>
													<h:outputText value="#{_service.name}" />
												</p:column>
												<p:column>
													<h:outputText value="#{_service.qualificationClass.name}" />
												</p:column>
											</p:row>
										</p:repeat>
									</p:panelGrid>
								</p:column>
							</p:row>
						</p:panelGrid>
					</p:repeat>
				</p:panel>
				
				<p:panel id="reqs" header="资质要求"
					rendered="#{bulletinHome3.instance.qualificationGroup.getQualificationGroups().size () > 0}"
					style="margin-bottom:10px;">
					<h:outputText
						value="#{bulletinHome3.instance.qualificationGroup.getQualificationGroupDetail()}" />
				</p:panel>
			</p:panel>
			
			<p:remoteCommand name="updateAttachments" update="@form:applyPanel,@form:reportDataPanel"></p:remoteCommand>
			
			<p:panel id="applyPanel" header="公告要求材料" style="margin-top: 10px;" rendered="#{bulletinHome3.instance.wayOfChoose != 'Best'}">
				<p:panelGrid>
					<p:repeat var="_def" value="#{bulletinHome3.instance.defs}" varStatus="_status">
						<p:row>
							<p:column>
								<div style="width: 100px; margin: 0;">
									<p:outputLabel for="applyAttachment" value="#{_def.requiredName}"></p:outputLabel>
								</div>								
							</p:column>
							<p:column>
								<p:fileUpload 
									id="applyAttachment"
									required="#{_def.required}"
									invalidSizeMessage="附件大小不能超过3M!"
									sizeLimit="#{1024 * 1024 * 3}"
									mode="advanced"
									uploadLabel="上传"
									cancelLabel="取消"
									oncomplete="updateAttachments()"
									fileUploadListener="#{tradeController.uploadAttachment}"></p:fileUpload>
								<p:panel id="uploadedAttachments" >
									<ul>
										<p:repeat  var="_attachment" value="#{tradeController.uploadMap[_status.index]}">
											<li>
												<h:outputText value="#{_attachment.filename}" />
												<span style="padding-left:8px;">
													<p:commandLink  action="#{tradeController.removeAttachment(_status.index,_attachment)}" value="x" immediate="true" oncomplete="updateAttachments()"></p:commandLink>
												</span>
											</li>
										</p:repeat>
									</ul>
								</p:panel>
							</p:column>
						</p:row>
					</p:repeat>	
				</p:panelGrid>				
			</p:panel>
			
			<p:panel id="reportDataPanel" header="上报报名材料" style="margin-top: 10px;" rendered="#{bulletinHome3.instance.wayOfChoose == enumUtils.getEnum('ChooseType', 'Best')}">
				<h2 style="color:red;margin:10px;text-align:left;">请提交公告内要求提报的所有报名材料，同时必须保证所提交资料的真实有效性，否则将负法律责任并将影响最后的选取结果</h2>
				<h:panelGrid columns="2" cellpadding="5" style="margin-bottom:5px;" >
		        	<p:outputLabel
						for="offer"
						value="报价"
					/>
					<p:inputNumber id="offer"
							  value="#{tradeController.instance.tradeReportData.offer}"
						   required="true" 
						   decimalPlaces="2"
					   autocomplete="off" />
				</h:panelGrid>
				<p:panelGrid>
					<p:repeat var="_def" value="#{bulletinHome3.instance.defs}" varStatus="_status">
						<p:row>
							<p:column>
								<div style="width: 100px; margin: 0;">
									<p:outputLabel for="applyAttachment" value="#{_def.requiredName}"></p:outputLabel>
								</div>								
							</p:column>
							<p:column>
								<p:fileUpload 
									id="applyAttachment"
									required="#{_def.required}"
									invalidSizeMessage="附件大小不能超过3M!"
									sizeLimit="#{1024 * 1024 * 3}"
									mode="advanced"
									uploadLabel="上传"
									cancelLabel="取消"
									oncomplete="updateAttachments()"
									fileUploadListener="#{tradeController.uploadAttachment}"></p:fileUpload>
								<p:panel id="uploadedAttachments" >
									<ul>
										<p:repeat  var="_attachment" value="#{tradeController.uploadMap[_status.index]}">
											<li>
												<h:outputText value="#{_attachment.filename}" />
												<span style="padding-left:8px;">
													<p:commandLink  action="#{tradeController.removeAttachment(_status.index,_attachment)}" value="x" immediate="true" oncomplete="updateAttachments()"></p:commandLink>
												</span>
											</li>
										</p:repeat>
									</ul>
								</p:panel>
							</p:column>
						</p:row>
					</p:repeat>	
				</p:panelGrid>	
			</p:panel>
			
			<p:commandButton value="请先仔细阅读公告后，再报名！"
							ajax = "true"
					styleClass="applyBtn"	
					widgetVar="applyBtn"	
				 	rendered="#{tradeController.instance.supplierCanApply()}"
				 	update="@form"
				 	oncomplete="PF('infoTip').show();"
				  	action="#{tradeController.saveAndFlush()}" />
			<p:commandButton rendered="#{tradeController.instance.supplierCanApply()}" action="#{tradeController.cancel()}" value="取消" immediate="true"></p:commandButton>
			
		</h:form>
      	
      	<p:dialog id="infoTip" closable="true" showEffect="true" widgetVar="infoTip" width="666" height="300" modal="true" >
			<p:panel>
				<f:facet name="header">提示信息</f:facet>
				<p:messages id="messages">
		       		<p:autoUpdate />
		       	</p:messages>
				<f:facet name="footer">
					<p:button value="查看已收到邀请的项目！"
						outcome="/business/supplier/UnapplyTradeList.xhtml" />
					<p:button value="查看已报名的项目" outcome="/business/supplier/AppliedTradeList.xhtml"/>
				</f:facet>
			</p:panel>
	   	</p:dialog>
	   	
      	<script>
      		PF('applyBtn').disable();
			var inital = 10;
			setInterval('countDown()',1000);
			function countDown(){
				if(inital > 0){
					$(".applyBtn").find("span").text("我已详细阅读公告（"+inital+"s）");
				}else{
					PF('applyBtn').enable();
					$(".applyBtn").find("span").text("申请");
				}
				inital = inital - 1;
			}
		</script>
   	</ui:define>
</ui:composition>
